package components.dialogs.adjustments
{
	import UIFree.ObjectEvent;
	import UIFree.command.uif_commandManager;
	import UIFree.uif_component;
	
	import classes.Commands.c_applyColorTransform;
	
	import components.dialogs.c_elementPropDlg;
	import components.dialogs.c_propertyDialog;
	import components.editor.c_baseElement;
	
	import flash.display.ColorCorrection;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	
	public class c_BRCN extends c_elementPropDlg {
		private var _safeMatrix: ColorTransform;
		
		public function c_BRCN(parent: uif_component, a_element: c_baseElement, a_title:String='', modal:Boolean=false) {
			_safeMatrix	= new ColorTransform();
			_safeMatrix.concat(a_element.transform.colorTransform);
			
			super(parent, a_element, [
				{
					title	: 'Контрастность',
					type	: c_propertyDialog.PTYPE_NUMBER,
					value	: 50
				},{
					title	: 'Яркость',
					type	: c_propertyDialog.PTYPE_NUMBER,
					value	: 50
				},{
					title	: 'Прозрачность',
					type	: c_propertyDialog.PTYPE_NUMBER,
					value	: 100
				}					
			], a_title, modal);
		}
		
		override protected function updateElement(): void {
			var ct: ColorTransform = new ColorTransform();
			ct.concat(_safeMatrix);
			ct.concat(matrix);
			element.transform.colorTransform = ct;
		}
		
		protected function get matrix(): ColorTransform {
			var br		: Number = (values[1].value - 50) / 100;
			var con		: Number = (50 + values[0].value) / 100;
			var offset	: Number = 0x7F * (1 - con) + 0xFF * br;
			
			return new ColorTransform(
				con,
				con,
				con,
				values[2].value / 100,
				offset,
				offset,
				offset
			); 
		}
		
		override protected function doCancel():void {
			element.transform.colorTransform = _safeMatrix;
		}
		
		override protected function doApply():void {
			element.transform.colorTransform = _safeMatrix;
			executeCommand(new c_applyColorTransform(element, matrix));
		}
	}
}